package com.me.demo.controller;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.me.demo.pojo.*;
import com.me.demo.utility.ThreadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RedisController {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    /**
     * redis功能测试
     * @return
     */
    @RequestMapping("redis")
    public String testRedis() {
        String name = stringRedisTemplate.opsForValue().get("name");
        return name;
    }

    /**
     * 启动所有数据接口
     * @return 启动信息
     */
    @RequestMapping("start")
    public String startRedis() {
        ThreadService.requestHttpPostConnection(2000);
        return "数据刷新启动";
    }

    /**
     * 日期值班信息组件数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data1")
    public String riQiZhiBanXinXiData() throws JsonProcessingException {
        RiQiZhiBanXinXiModel model = ThreadService.runRiQiZhiBanXinXiDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data1", json);
        System.out.println(String.format("发送到客户端的数据是-----%s", json));
        return String.format("发送到客户端的数据是-----data1：%s", json);
    }

    /**
     * 安全运营天数组件数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data2")
    public String anQuanYunYingTianShuData() throws JsonProcessingException {
        AnQuanYunYingTianShuModel model = ThreadService.runAnQuanYunYingTianShuDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data2", json);
        System.out.println(String.format("发送到客户端的安全运营天数数据是-----%s", json));
        return String.format("发送到客户端的安全运营天数数据是-----data2：%s", json);
    }

    /**
     * 车站报警排名组件数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data3")
    public String cheZhanBaoJingPaiMingData() throws JsonProcessingException {
        CheZhanBaoJingPaiMingModel model = ThreadService.runCheZhanBaoJingPaiMingDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data3", json);
        System.out.println(String.format("发送到客户端车站报警次数排名的数据是-----%s", json));
        return String.format("发送到客户端车站报警次数排名的数据是-----data3：%s", json);
    }

    /**
     * 主变负荷组件数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data4")
    public String zhuBianFuHeData() throws JsonProcessingException {
        ZhuBianFuHeModel model = ThreadService.runZhuBianFuHeDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data4", json);
        System.out.println(String.format("发送到客户端主变负荷的数据是-----%s", json));
        return String.format("发送到客户端主变负荷的数据是-----data4：%s", json);
    }

    /**
     * 专业报警矩阵组件数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data5")
    public String zhuanYeBaoJingJuZhenData() throws JsonProcessingException {
        ZhuanYeBaoJingJuZhenModel model = ThreadService.runZhuanYeBaoJingJuZhenDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data5", json);
        System.out.println(String.format("发送到客户端专业报警矩阵的数据是-----%s", json));
        return String.format("发送到客户端专业报警矩阵的数据是-----data5：%s", json);
    }

    /**
     * 能耗趋势图组件数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data6")
    public String nengHaoQuShiData() throws JsonProcessingException {
        NengHaoQuShiModel model = ThreadService.runNengHaoQuShiDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data6", json);
        System.out.println(String.format("发送到客户端能耗趋势的数据是-----%s", json));
        return String.format("发送到客户端能耗趋势的数据是-----data6：%s", json);
    }

    /**
     * 列车行车指标组件数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data7")
    public String lieCheXingCheZhiBiaoData() throws JsonProcessingException {
        LieCheXingCheZhiBiaoModel model = ThreadService.runlieCheXingCheZhiBiaoDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data7", json);
        System.out.println(String.format("发送到客户端列车行车指标的数据是-----%s", json));
        return String.format("发送到客户端列车行车指标的数据是-----data7：%s", json);
    }

    /**
     *车站客流排名组件数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data8")
    public String cheZhanKeLiuPaiMingData() throws JsonProcessingException {
        CheZhanKeLiuPaiMingModel model = ThreadService.runCheZHanKeLiuPaiMingDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data8", json);
        System.out.println(String.format("发送到客户端车站客流排名指标的数据是-----%s", json));
        return String.format("发送到客户端车站客流排名指标的数据是-----data8：%s", json);
    }

    /**
     *车站客流趋势图数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data9")
    public String cheZhanKeLiuQuShiTuData() throws JsonProcessingException {
        CheZhanKeLiuQuShiTuModel model = ThreadService.runCheZhanKeLiuQuShiTuDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data9", json);
        System.out.println(String.format("发送到客户端车站客流趋势图的数据是-----%s", json));
        return String.format("发送到客户端车站客流趋势图指标的数据是-----data9：%s", json);
    }

    /**
     * 列车实时报点信息数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data10")
    public String lieCheShiShiBaoDianXiniData() throws JsonProcessingException {
        LieCheBaoDian model = ThreadService.runLieCheShiShiBaoDianXinXiDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data10", json);
        System.out.println(String.format("发送到客户端列车实时报点组件的数据是-----%s", json));
        return String.format("发送到客户端列车实时报点组件的数据是-----data10：%s", json);
    }

    /**
     * 月进站客流趋势数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data11")
    public String yueJinZhanKeLiuQuShiData() throws JsonProcessingException {
        YueJinZhanKeLiuQuShiModel model = ThreadService.runYueJinZhanKeLiuQuShiDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data11", json);
        System.out.println(String.format("发送到客户端月进站客流趋势组件的数据是-----%s", json));
        return String.format("发送到客户端月进站客流趋势组件的数据是-----data11：%s", json);
    }

    /**
     * 月行车趋势数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data12")
    public String yueXingCheQuShiData() throws JsonProcessingException {
        YueXingCheQuShiModel model = ThreadService.runYueXingCheQuShiDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data12", json);
        System.out.println(String.format("发送到客户端月行车趋势组件的数据是-----%s", json));
        return String.format("发送到客户端月行车趋势组件的数据是-----data12：%s", json);
    }

    /**
     * 月能耗趋势数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data13")
    public String yueNengHaoQuShiData() throws JsonProcessingException {
        YueNengHaoQuShiModel model = ThreadService.runYueNengHaoQuShiDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data13", json);
        System.out.println(String.format("发送到客户端月能耗趋势组件的数据是-----%s", json));
        return String.format("发送到客户端月能耗趋势组件的数据是-----data13：%s", json);
    }

    /**
     * 站年客流排名数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data14")
    public String zhanNianKeLiuPaiMingData() throws JsonProcessingException {
        ZhanNianKeLiuPaiMingModel model = ThreadService.runZhanNianKeLiuPaiMingDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data14", json);
        System.out.println(String.format("发送到客户端站年客流排名组件的数据是-----%s", json));
        return String.format("发送到客户端站年客流排名组件的数据是-----data14：%s", json);
    }

    /**
     * 行车指标数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data15")
    public String xingCheZhiBiaoData() throws JsonProcessingException {
        XingCheZhiBiaoModel model = ThreadService.runXingCheZhiBiaoDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data15", json);
        System.out.println(String.format("发送到客户端行车指标组件的数据是-----%s", json));
        return String.format("发送到客户端站行车指标组件的数据是-----data15：%s", json);
    }

    /**
     * 能耗类型占比数据接口
     * @return 带组件需要信息的json串
     * @throws JsonProcessingException
     */
    @RequestMapping("data16")
    public String nengHaoLeiXingZhanBiData() throws JsonProcessingException {
        NengHaoLeiXingZhanBiModel model = ThreadService.runNengHaoLeiXingZhanBiDataTask(2000);
        ObjectMapper mapper = new ObjectMapper();
        String json = mapper.writeValueAsString(model);
        stringRedisTemplate.convertAndSend("data16", json);
        System.out.println(String.format("发送到客户端能耗类型占比组件的数据是-----%s", json));
        return String.format("发送到客户端能耗类型占比组件的数据是-----data16：%s", json);
    }
}
